package com.base.cn.platform.os.controller.mobile.user.center.member;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.manage.order.goods.OrderDetailsService;
import com.base.cn.platform.os.service.manage.user.member.CusUserMemberBuyRecordService;
import com.base.cn.platform.os.service.manage.user.member.CusUserMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 我的会员
 * @author ll
 * @date 2018/7/4 14:51
 */
@Controller
@RequestMapping("/mobile/uc/member")
public class MobileUserMemberController extends MobileBaseController {

    @Autowired
    private CusUserMemberBuyRecordService cusUserMemberBuyRecordService;
    @Autowired
    private OrderDetailsService orderDetailsService;
    @Autowired
    private CusUserMemberService cusUserMemberService;

    /**
     * 会员
     * @param request
     * @return
     */
    @RequestMapping("/myMember")
    public String myMember(HttpServletRequest request){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String,Object> record =cusUserMemberBuyRecordService.queryUserBuyMemberRecord(userId);
        request.setAttribute("userMemberBuyRecord",record);
        return resultPage("/user/center/member/u-member");
    }

    /**
     * 会员我的记录
     *
     * @param request
     * @return
     */
    @RequestMapping("/ajax/userMemberBuyRecord")
    public String userMemberBuyRecord(Model model, HttpServletRequest request,
                                      @RequestBody Map<String,Object> params,
                                      @RequestParam(value = "currentPage",required = false,defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        params.put("userId",userId);
        params.put("shopType","MEMBER");
        params.put("statusList","'SUCCESS','REFUND'");
        Map<String, Object> dataMap = orderDetailsService.findOrderDetailsPage(params,currentPage,false,true,false);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/center/member/ajax-user-member-record");
    }

    /**
     * 查询所有的会员数据列表
     * @param model
     * @return
     */
    @RequestMapping("/queryAllMemberList")
    public String queryAllMemberList(Model model){
        Map<String,Object> parmas = new HashMap<>();
        parmas.put("status",1);
        parmas.put("memberType",1);
        List<Map<String,Object>> userMemberList = cusUserMemberService.queryUserMemberList(parmas);
        model.addAttribute("userMemberList",userMemberList);
        return resultPage("/user/center/member/member-list");
    }
}
